package org.springblade.modules.admin.vo.plan.store;

import cn.hutool.core.convert.Convert;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainPlanTemplate;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 评分-维修，保养历史
 *
 * @author zcc
 * @version 1.0
 * @date 2025/3/4 9:34
 */
@Data
public class WxByPlanHistoryVo {

	@ApiModelProperty("工单id")
	private Long planId;

	@ApiModelProperty("故障字典的key")
	private String problemItem;

	@ApiModelProperty("工单时间")
	private String planDate;

	@ApiModelProperty("工单文案描述维修:表示故障原因,保养时表示模板名称")
	private String planDesc;

	@ApiModelProperty("执行人")
	private String userNames;


	private String templateNames;


	public void setTemplateNames(String templateNames) {
		if(Func.isNotEmpty(templateNames) && templateNames.contains("%")){
			List<String> strings = Func.toStrList(templateNames);
			List<String> planCheckNames = new ArrayList<>(16);
			List<MaintainPlanTemplate> list = new ArrayList<>(10);
			for (String str :strings) {
				String[] split = str.split("%");
				MaintainPlanTemplate maintainPlanTemplate = new MaintainPlanTemplate();
				maintainPlanTemplate.setTemplateName(split[0] + "-" + split[1]);
				planCheckNames.add(split[1]);
				maintainPlanTemplate.setSort(Convert.toInt(split[2],0));
				list.add(maintainPlanTemplate);
			}
			List<String> collect = list.stream().sorted(Comparator.comparing(MaintainPlanTemplate::getSort)).map(MaintainPlanTemplate::getTemplateName).collect(Collectors.toList());
			this.templateNames = String.join(",",collect);
			this.planDesc = String.join(",",planCheckNames);
		}else {
			this.templateNames = templateNames;
		}
	}

}
